#ifndef _SLIST_H_
#define _SLIST_H_

#include "mem_chunk.h"

typedef void z_destroy_notify (void *data);
typedef struct z_slist z_slist;
typedef struct z_slist_node z_slist_node;

/* @breif Single-linked list
 */
struct z_slist
{
  z_slist_node *head;
  z_slist_node *tail;
};

/* @breif single-linked list node
 */
struct z_slist_node
{
  z_slist_node *next;
  void *data;
};

/* Allocate a single-linked list
 * */
z_slist* z_slist_alloc(void);

/* Destroy the contents of a single-linked list
 * @param slist a lsit
 */
void z_slist_destroy(z_slist *slist, z_destroy_notify destroy_func) __attribute__((nonnull(1)));

/* Free a single-linked list
 * @param slist a s_list
 * */
void z_slist_free(z_slist *slist);

/* Append to a single-linked lsit
 * @param slist a list
 * @param data the data
 * */
void z_slist_append(z_slist *slist, void *data)__attribute__((nonnull(1)));

/* Append to a single-linked list with chunk memory
 * @param slist a lsit
 * @param data the data
 * @param mem_chunk a z_mem_chunk for allocation of new node
 * */
void z_slist_append_chunk(z_slist *slist, void *data, z_mem_chunk *mem_chunk)__attribute__((nonnull(1, 3)));

/* Prepend to a single-linked list
 * @param slist a list
 * @param data the data
 * */
void z_slist_prepend(z_slist *slist, void *data)__attribute__((nonnull(1)));

/* Prepend to a single-linked list with chunk memory
 * @param slist a list
 * @param *data the data
 * @param mem_chunk the chunk memory for list
 * */
void z_slist_prepend_chunk(z_slist *slist, void *data, z_mem_chunk* mem_chunk)__attribute__((nonnull(1,3)));

#endif /* _SLIST_H_ */
